package com.jk.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.jk.mapper.UserMapper;
import com.jk.model.ProductBean;
import com.jk.model.UserBean;
import com.jk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Component
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Integer getCount() {
        Integer count = userMapper.getCount();
        return count;
    }
    /**
     * 根据商品id 查询商品详细内容
     * @return
     */
    @Override
    public ProductBean queryProductInfoById(Integer id) {

        return userMapper.queryProductInfoById(id);
    }
    /**
     * 审核商品
     * @param page
     * @param rows
     * @param userBean
     * @return
     */
    @Override
    public Map findShopProductList(Integer page, Integer rows, UserBean userBean) {
        HashMap<String, Object> result = new HashMap<>();
        HashMap<String, Object> param = new HashMap<>();
        param.put("userBean", userBean);
        int count=userMapper.findShopProductCount(param);
        result.put("total", count);
        param.put("startIndex", (page-1)*rows);
        param.put("endIndex", rows);
        List<UserBean> list=userMapper.findShopProductList(param);
        result.put("rows", list);
        return result;
    }
    /**
     * 审核商品的操作
     * @param falg
     * @return
     */
    @Override
    public void pizhun(Integer id, Integer falg) {
        userMapper.pizhun(id,falg);
    }

    /**
     * 查询收藏夹中的内容 mongodb
     * 根据收藏夹中的商品Id 查询已经上架的商品
     * @param productId
     * @return
     */
    @Override
    public ProductBean queryProductByInfoProductId(Integer productId) {
        return userMapper.queryProductInfoById(productId);
    }
}
